﻿@{
    ViewBag.Title = "文章列表";
}
@section scripts{
    <script type="text/javascript">
        var $tbGrid = {};
        var passRowData = '';
        $(function() {
            $('#addText').dialog({
                title: '审核意见',
                iconCls: 'icon-add',
                shadow: true,
                buttons: [
                    {
                        text: '确认',
                        iconCls: 'icon-ok',
                        handler: function() {
                            $('#addText').dialog('close');
                        }
                    }
                ]
            }).dialog('close');

            $.globalParas.datagrid.url = '@Url.Action("GetArticlePage", "Manager", new {area = "Users"})';
            $.globalParas.datagrid.columns = [
                [
                    { field: 'Title', title: '标题', width: 140, align: 'center', formatter: dgvFormat },
                    { field: 'Tags', title: '标签', width: 140, align: 'center', formatter: dgvFormat },
                    { field: 'CommentCount', title: '评论数', width: 30, align: 'center', formatter: dgvFormat },
                    { field: 'VisitCount', title: '浏览数', width: 30, align: 'center' },
                    {
                        field: 'ApprovedPass',
                        title: '通过审核',
                        width: 40,
                        align: 'center',
                        formatter: function(value) {
                            return value === true
                                ? '<span class = "font-green">是</span>'
                                : '<span class = "font-red">否</span>';
                        }
                    },
                    { field: 'ApprovedInfo', title: '审核信息', width: 80, align: 'center', formatter: dgvFormat },
                    { field: 'WriteTime', title: '发布时间', width: 60, align: 'center' }
                ]
            ];
            $.globalParas.datagrid.idField = 'Id';
            $.globalParas.datagrid.loadFilter = function(response) {
                if (response.Statu === 1) {
                    return response.Data;
                } else
                    $.msgBoxObj.showMsgErr(response.Msg, true);
            };
            $.globalParas.datagrid.bindBtnEvent('新增', function() {
                window.top.open('@Url.Action("AddBlog","Blog",new {area = "Blogs"})');
            });
            // 为'修改'按钮添加事件绑定
            $.globalParas.datagrid.bindBtnEvent('修改',
                function() {
                    // 获取选定的数据
                    var rowData = $tbGrid.datagrid('getSelected');
                    // 判断是否选定了数据
                    if (rowData) {
                        $.globalParas.showComWindowObj({
                            title: '编辑文章',
                            width: 800,
                            height: 700,
                            url: '@Url.Action("EditArticle", "Manager", new {area = "Users"})' + '?Id=' + rowData.Id,
                            callObject: $('#tbGrid')
                        });
                    } else
                        window.top.$.msgBoxObj.showMsgErr('未选定任何行!');
                });
            $.globalParas.datagrid.addBtn('查看',
                function() {
                    // 获取选定的数据
                    var rowData = $tbGrid.datagrid('getSelected');
                    // 判断是否选定了数据
                    if (rowData) {
                        window.open('@Url.Content("~/Article")/' + rowData.Id+'.shtml');
                    } else
                        window.top.$.msgBoxObj.showMsgErr('未选定任何行!', true);
                },
                'icon-search');
            // 添加删除按钮
            $.globalParas.datagrid.bindBtnEvent('删除',
                function() {
                    // 获取选定的数据
                    var rowData = $tbGrid.datagrid('getSelected');
                    // 判断是否选定了数据
                    if (rowData) {
                        // 用户重复确认是否删除
                        window.top.$.messager.confirm('确认',
                            '您确认要删除记录吗？删除后无法恢复！',
                            function(isOk) {
                                if (isOk) {
                                    $.ajax({
                                        url: '@Url.Action("DeleteArticle", "Manager", new {area = "Users"})',
                                        type: 'Delete',
                                        data: { Id: rowData.Id },
                                        error: function() {
                                            // 提示网络错误
                                            $.msgBoxObj.showMsgErr('网络错误!');
                                        },
                                        success: function(response) {
                                            $.processJsonMsg(response,
                                                function() {
                                                    $tbGrid.datagrid('reload');
                                                });
                                        }
                                    });
                                }
                            });
                    } else
                        window.top.$.msgBoxObj.showMsgErr('未选定任何行!', true);
                });
            $.globalParas.datagrid.addBtn('查看审核意见',
                function() {
                    // 获取选定的数据
                    var passRowData = $tbGrid.datagrid('getSelected');
                    // 判断是否选定了数据
                    if (passRowData) {
                        $('#add-text').textbox('setValue', passRowData.ApprovedInfo);
                        $('#addText').dialog('center').dialog('open');
                    } else
                        window.top.$.msgBoxObj.showMsgErr('未选定任何行!', true);
                },
                'icon-ok');
            $.globalParas.datagrid.addBtn('允许/禁止评论',
                function() {
                    // 获取选定的数据
                    var passRowData = $tbGrid.datagrid('getSelected');
                    // 判断是否选定了数据
                    if (passRowData) {
                        $('#add-text').textbox('setValue', passRowData.ApprovedInfo);
                        $('#addText').dialog('center').dialog('open');
                    } else
                        window.top.$.msgBoxObj.showMsgErr('未选定任何行!', true);
                },
                'icon-no');
            // 初始化Grid控件
            $tbGrid = $("#tbGrid").datagrid($.globalParas.datagrid);
        });
    </script>
}
<table id="tbGrid"></table>
<div id="addText" style="width:400px;height:300px; padding: 10px;display: none">
    <input type="text" readonly="readonly" id="add-text" data-options="multiline:true" class="easyui-textbox" style="margin: 10px; width: 100%; height: 180px">
</div>